package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import bean.AppInfoVo;
import bean.AppType;
import bean.AppVo;
import bean.Comment;
import bean.Comments;
import bean.CommentsVO;
import bean.CoolIdea;
import bean.CoolIdeaVO;
import bean.Review;
import bean.ReviewVO;
import bean.Tucao;
import bean.TucaoVO;

public class AppDao{
	

	@SuppressWarnings("unchecked")
	public List<AppVo> findAppEntry(String userId)
	{
		Statement sta = null;
		List entryList = new ArrayList();
		AppVo app = null;
		try {
			StringBuffer sql = new StringBuffer();
			sql.append(" select entrys.id,entrys.plistDbxUrl,entrys.logo,app.name,apptype.type,entrys.plistUrl,entrys.schemesUrl,entrys.ipaSize, ");
			sql.append(" entrys.developers,entrys.createTime, entrys.version,entrys.description");
			sql.append(" from a_app as app ");
			sql.append(" inner join a_apptype as apptype on apptype.id = app.appTypeid");
			sql.append(" inner join a_appentry as entrys on entrys.id = app.nowAppEntryId");
			//sql.append(" LEFT JOIN a_appphoto as photo on photo.appEntryid =  entrys.id ");\
			PooledConn pooledConn = new PooledConn();
			ResultSet rs = pooledConn.getInstance().executeQuery(sql.toString());
			while (rs.next()) {
				app = new AppVo();
				app.setId(rs.getString("id"));
				app.setLogo(rs.getString("logo"));
				app.setName(rs.getString("name"));
				app.setType(rs.getString("type"));
				app.setSchemesUrl(rs.getString("schemesUrl"));
				app.setDevelopers(rs.getString("developers"));
				app.setCreateTime(rs.getTimestamp("createTime"));
				app.setVersion(rs.getString("version"));
				app.setDescription(rs.getString("description"));
				app.setIpaSize(rs.getString("ipaSize"));
				app.setPlistDbxUrl(rs.getString("plistDbxUrl"));
				entryList.add(app);
			}
//			ConnectionFactory.commit();
		} catch (SQLException e) {
//			ConnectionFactory.roolback();
			e.printStackTrace();
			
//			if (sta != null)
//				try {
//					sta.close();
//				}
//			catch (SQLException e1) {
//				e1.printStackTrace();
//			}
		}
		finally
		{
//			PooledConn.getInstance().close();
		}
		
//	    if (app != null)
//	      entryList = findApp(app.getId(), app.getId());
//	    else {
//	      entryList = findApp(userId, null);
//	    }
		
		return entryList;
	}
}